Virtual Memory

Zhao Cong

Virtual Memory(General Cache)

the main memory can act as a “cache” for the secondary storage, usually implemented with magnetic disks.This technique is called virtual memory(A technique that uses main memory as a “cache” for secondary storage)

Major Motivations for Virtual Memory

  1. allow efficient and safe sharing of memory among multiple programs, such as for the memory needed by multiple virtual machines for cloud computing
  2. remove the programming burdens of a small, limited amountof main memory

Physical Address and Virtual Address

  1. physical addresses:An address in main memory(sometimes called physical memory to distinguish it from virtual memory)
  2. protection:A set of mechanisms for ensuring that multiple processes sharing the processor, memory, or I/O devices cannot interfere, intentionally or unintentionally, with one another by reading or writing each other’s data. These mechanisms also isolate the operating system from a user process.
  3. Page:A virtual memory block is called a page
  4. page fault:An event that occurs when an accessed page is not present in main memory.(a virtual memory miss)
  5. virtual address:An address that corresponds to a location in virtual space and is translated by address mapping to a physical address when memory is accessed
  6. address translation:Also called address mapping. The process by which a virtual address is mapped to an address used to access memory. If we return to our library analogy, we can think of a virtual address as the title of a book and a physical address as the location of that book in the library, such as might be given by the Library of Congress call number.
  7. Virtual memory also simplifies loading the program for execution by providing relocation. Furthermore, all virtual memory systems in use today relocate the program as a set of fixed-size blocks (pages), thereby eliminating the need to find a contiguous block of memory to allocate to a program; instead, the operating system need only find a sufficient number of pages in main memory.
  8. In virtual memory, the address is broken into a virtual page number and a page offset(determines the page size). The physical page number constitutes the upper portion of the physical address, while the page offset, which is not changed, constitutes the lower portion. Having a larger number of virtual pages than physical pages is the basis for the illusion of an essentially unbounded amount of virtual memory
  9. several key decisions in designing virtual memory systems:
    • Pages should be large enough to try to amortize the high access time
    • Organizations that reduce the page fault rate are attractive
    • Page faults can be handled in software because the overhead will be small compared to the disk access time
    • Write-through will not work for virtual memory, since writes take too long. Instead, virtual memory systems use write-back

Elaboration:time-sharing systems, segmentation and Paging

Page Table and Page Table Register

  1. page table:The table containing the virtual to physical address translations in a virtual memory system. The table, which is stored in memory, is typically indexed by the virtual page number; each entry in the table contains the physical page number for that virtual page if the page is currently in memory.
  2. page table register:To indicate the location of the page table in memory, the hardware includes a register that points to the start of the page table; we call this the page table register. Hardware/ Software Interface
    1. The page table, together with the program counter and the registers, specifies the state of a virtual machine.We often refer to this state as a process.
    2. The process is considered active when it is in possession of the processor; otherwise, it is considered inactive.
    3. Rather than save the entire page table, the operating system simply loads the page table register to point to the page table of the process it wants to make active. Each process has its own page table, since different processes use the same virtual addresses.
    4. The use of separate page tables also provides protection of one process from another.
  3. valid bit:
    • If the bit is off, the page is not present in main memory and a page fault occurs
    • If the bit is on, the page is in memory and the entry contains the physical page number
  4. Because the page table contains a mapping for every possible virtual page, no tags are required.

Page Faults

replacement strategy

  1. swap space:The space on the disk reserved for the full virtual memory space of a process Hardware/ Software Interface reference bit: Also called use bit. A field that is set whenever a page is accessed and that is used to implement LRU(least recently used) or other replacement schemes. The operating system periodically clears the reference bits and later records them so it can determine which pages were touched during a particular time period.

writing strategy

  1. In a virtual memory system, writes to the next level of the hierarchy (disk) can take millions of processor clock cycles, virtual memory systems must use write-back.
  2. To track whether a page has been written since it was read into the memory, a dirty bit is added to the page table. The dirty bit is set when any word in a page is written

Making Address Translation Fast: the TLB

  1. translation-lookaside buffer (TLB): A cache that keeps track of recently used address mappings to try to avoid an access to the page table.
  2. If a miss in the TLB occurs, we must determine whether it is a page fault or merely a TLB miss
    • If the page exists in memory, then the TLB miss indicates only that the translation is missing
    • If the page is not present in memory, then the TLB miss indicates a true page fault

Integrating Virtual Memory, TLBs, and Caches

  1. that data cannot be in the cache unless it is present in main memory aliasing, physically addressed cache

Implementing Protection with Virtual Memory

Handling TLB Misses and Page Faults

Summary